﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
using Entity;

namespace DataControls
{
    public class LUONGCB_Data
    {
       
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public Boolean kiemtra_MaLuongCB(String maluongcb)
        {
            int i = 0;
            String excuteString = "SELECT COUNT(*) FROM BANGLUONGCB WHERE MALUONGCB='" + maluongcb + "'";
            i = dataBaseAccess.Test(excuteString);
            if (i > 0)
                return true;
            else
                return false;
        }

        public Boolean kiemtra_GiaoVien(LUONGCB luongcb)
        {
            int i = 0;
            String excuteString = "SELECT COUNT(*) FROM BANGLUONGCB WHERE MAGV='" + luongcb.magv +
                                                        "' AND HOCKI =" + luongcb.hocki +
                                                        " AND NAMHOC=" + luongcb.namhoc+ "";
            i = dataBaseAccess.Test(excuteString);
            if (i > 0)
                return true;
            else
                return false;
        }

        public void layten_GiaoVien(String magiaovien, ComboBox cb)
        {
            try
            {
                int a = 0;
                String excuteString = "SELECT TENGV FROM GIAOVIEN WHERE MAGV='" + magiaovien + "'";
                String tengiaovien = dataBaseAccess.excuteReader(excuteString);
                for (int i = 0; i < cb.Items.Count; i++)
                {
                    cb.SelectedIndex = i;
                    if (tengiaovien.Equals(((ListItem)(cb.SelectedItem)).name))
                        a = i;
                }
                cb.SelectedIndex = a;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
